package com.nmc.action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.interceptor.ServletRequestAware;

import com.commons.AjaxHelper;
import com.metaparadigm.jsonrpc.JSONRPCBridge;
import com.nmc.core.manager.WardManager;
import com.nmc.core.manager.ZoneManager;
import com.opensymphony.xwork2.ActionSupport;

public class SearchAction extends ActionSupport implements ServletRequestAware {

	private WardManager wardManager;
	private ZoneManager zoneManager;
	private List zoneList = new ArrayList();	
	private List wardList = new ArrayList();		
	HttpServletRequest request;
	private boolean resultPage;
	private String searchTxt;
	private String zoneId;
	private String wardId;
	
	
	public String home() throws Exception
    {
		JSONRPCBridge json_bridge = null;
		json_bridge = (JSONRPCBridge) request.getSession().getAttribute("JSONRPCBridge");
		if (json_bridge == null) {
			json_bridge = new JSONRPCBridge();
			request.getSession().setAttribute("JSONRPCBridge", json_bridge);
		}
		json_bridge.registerObject("getZoneList", new AjaxHelper(request.getSession().getServletContext()));

    
        return this.SUCCESS;
    }
	
	public String zoneOffices()
	{
		return this.SUCCESS;
	}
	
	/**
	 * @return the searchTxt
	 */
	public String getSearchTxt() {
		return searchTxt;
	}

	/**
	 * @param searchTxt the searchTxt to set
	 */
	public void setSearchTxt(String searchTxt) {
		this.searchTxt = searchTxt;
	}

	/**
	 * @return the zoneId
	 */
	public String getZoneId() {
		return zoneId;
	}

	/**
	 * @param zoneId the zoneId to set
	 */
	public void setZoneId(String zoneId) {
		this.zoneId = zoneId;
	}

	/**
	 * @return the wardId
	 */
	public String getWardId() {
		return wardId;
	}

	/**
	 * @param wardId the wardId to set
	 */
	public void setWardId(String wardId) {
		this.wardId = wardId;
	}

	/**
	 * @param zoneList the zoneList to set
	 */
	public void setZoneList(List zoneList) {
		this.zoneList = zoneList;
	}

	public void setServletRequest(HttpServletRequest arg0) {
		this.request = arg0;
	}

	public String search() throws Exception {
			
			JSONRPCBridge json_bridge = null;
			json_bridge = (JSONRPCBridge) request.getSession().getAttribute("JSONRPCBridge");
			if (json_bridge == null) {
				json_bridge = new JSONRPCBridge();
				request.getSession().setAttribute("JSONRPCBridge", json_bridge);
			}
			json_bridge.registerObject("getZoneList", new AjaxHelper(request.getSession().getServletContext()));

			return SUCCESS;
		
	}
	public String searchTrack()
	{
		String flag = ERROR;
    		
        	
        	flag = SUCCESS;
        
    	
    	return flag;
	}
	/**
	 * @param wardManager the wardManager to set
	 */
	public void setWardManager(WardManager wardManager) {
		this.wardManager = wardManager;
	}

	/**
	 * @return the wardManager
	 */
	public WardManager getWardManager() {
		return wardManager;
	}

	/**
	 * @param zoneManager the zoneManager to set
	 */
	public void setZoneManager(ZoneManager zoneManager) {
		this.zoneManager = zoneManager;
	}

	/**
	 * @return the zoneManager
	 */
	public ZoneManager getZoneManager() {
		return zoneManager;
	}

	public List getZoneList()
	{
		List list = zoneManager.getZoneList();
		if(list != null){
			zoneList = list;
		}
		return zoneList;
	}

	/**
	 * @param wardList the wardList to set
	 */
	public void setWardList(List wardList) {
		this.wardList = wardList;
	}

	/**
	 * @return the wardList
	 */
	public List getWardList() {
		//wardList = wardManager.getWardList();
		return wardList;
	}
	
}
